﻿using Interface.Utility.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interface.Core.Utility
{
    public static class ResultUtility
    {
        /// <summary>
        /// 反馈
        /// </summary>
        /// <param name="status"></param>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string Result(int status, string message = null, object data = null)
        {
            return JsonHelper.Serialize(new { status = status, message = message, data = data });
        }

        /// <summary>
        /// 反馈
        /// </summary>
        /// <param name="success"></param>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string Result(bool success, string message = null, object data = null)
        {
            return JsonHelper.Serialize(new { success = success, message = message, data = data });
        }

        /// <summary>
        /// 成功反馈
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string SuccessResult(string message = "操作成功!", object data = null)
        {
            return Result(true, message, data);
        }

        /// <summary>
        /// 失败反馈
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string FailureResult(string message = "操作失败!", object data = null)
        {
            return Result(false, message, data);
        }

        /// <summary>
        /// 未知反馈
        /// </summary>
        /// <param name="success"></param>
        /// <param name="successMessage"></param>
        /// <param name="failureMessage"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string UnknownResult(bool success, string successMessage = "操作成功!", string failureMessage = "操作失败!", object data = null)
        {
            if (success)
            {
                return SuccessResult(successMessage, data);
            }
            return FailureResult(failureMessage, data);
        }
    }
}